package com.itheima;
import java.util.function.BinaryOperator;
/**
 * @ProjectName: ybxy6
 * @Titile: TestLambda
 * @Author: Chilemey
 * @Description: TODO
 */
public class TestLambda {

    public static void main(String[] args) {
        testA();
        testC();
        testB();
        testD();
    }


    public static void testA() {
        A a1 = new A() {
            @Override
            public void show (String name, int age) {
                System.out.println(name + "," + age);
            }
        };

        A a2 = (name, age) -> System.out.println(name + "," + age);
        a2.show("张三", 18);

        A a3 = TestLambda::show2;
        a3.show("李四", 20);
    }

    public static void show2(String name, int age) {
        System.out.println(name + "," + age);
    }


    public static void testC() {
        C c1 = new C() {
            @Override
            public String show(String name) {
                return "name = " + name;
            }
        };
        System.out.println(c1.show("HelloC1"));
        C c2 = name -> "name = " + name;
        System.out.println(c2.show("HelloC2"));
    }

    public static void testB() {
        B b1 = new B() {
            @Override
            public void show(String name) {
                System.out.println(name);
            }
        };
        b1.show("hellob1");
        B b2 = name -> System.out.println(name);
        b2.show("hellob2");
    }

    public static void testD() {
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return Math.max(a, b);
            }
        };
        System.out.println("result1: " + d1.max(1, 2));

        D d2 = (a, b) -> a > b ? a : b;
        System.out.println("result2: " + d2.max(1, 2));

        BinaryOperator<Integer> d3 = Math::max;
        System.out.println("result3: " + d3.apply(1, 2));
    }
}